<?php

namespace easydis\APSBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use DateInterval;

/**
 * PlageHoraire
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="easydis\APSBundle\EntityRepository\PlageHoraireRepository")
 */
class PlageHoraire
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;
    
    /**
     * @var time
     *
     * @ORM\Column(name="hour_fin_eng", type="time")
     */
    private $heure_fin_eng;
    
    /**
     * @var time
     *
     * @ORM\Column(name="hour_debut_eng", type="time")
     */
    private $heure_debut_eng;
    
    /**
     * @var float
     *
     * @ORM\Column(name="temps", type="float")
     */
    private $temps;
    
    /**
     * @var string
     *
     * @ORM\Column(name="lib", type="string", length=100)
     */
    private $lib;
    
    /**
     * @ORM\ManyToOne(targetEntity="easydis\APSBundle\Entity\GroupeService")
     * @ORM\JoinColumn(nullable=false)
     */
    private $groupe_service;
    
    /**
     * @var ArrayCollection $children
     * 
     * @ORM\OneToMany(targetEntity="easydis\APSBundle\Entity\Planifier", mappedBy="plagehoraire", cascade={"remove"})
     */
    private $children;
    
    /**
     * @var boolean
     *
     * @ORM\Column(name="visibilite", type="boolean", length=2)
     */
    private $visibilite = true;
    
    /**
     * @var integer
     *
     * @ORM\Column(name="ordre", type="integer", length=4)
     */
    private $ordre = 1;
    
    
    
    public function __construct(){
        $this->children = new ArrayCollection();
    }

    public function setAll($hour_debut, $hour_fin, $gs) {
        //$this->temps = $this->heure_fin_eng->diff($this->heure_debut_eng);
        $this->groupe_service = $gs;
    }
    
    public function update_diff() {
        //$dateinterval = $this->heure_fin_eng->diff($this->heure_debut_eng);
        //$this->temps = date_create_from_format('h:i', $dateinterval->format('%h:%I'));
    }
    
    /**
     * @param easydis\APSBundle\Entity\Planifier $planif
     */
    public function addChildren($planif) {
        // Si l'objet fait déjà partie de la collection on ne l'ajoute pas
        if (!$this->children->contains($planif)) {
            $this->children->add($planif);
        }
    }
 
    /**
     * @return ArrayCollection $children
     */
    public function getChildren() {
        return $this->children;
    }
    
    /**
      * Set groupe_service
      *
      * @param easydis\APSBundle\Entity\GroupeService $groupe_service
      */
    public function setGroupeService(\easydis\APSBundle\Entity\GroupeService $groupe_service)
    {
            $this->groupe_service = $groupe_service;
    }

    /**
      * Get groupe_service
      *
      * @return easydis\APSBundle\Entity\GroupeService
      */
    public function getGroupeService()
    {
            return $this->groupe_service;
    }
    
    /**
     * Get heure_fin_eng
     *
     * @return time 
     */
    public function getHeurefinEng()
    {
        return $this->heure_fin_eng;
    }
    
    /**
     * Set hour_debut_eng
     *
     * @param datetime $temps
     * @return PlageHoraire
     */
    public function setHeurefinEng($temps)
    {
        $this->heure_fin_eng = $temps;
        
        if($this->heure_debut_eng != null) {
            $dateinterval = $this->heure_fin_eng->diff($this->heure_debut_eng);
            $this->temps = date_create_from_format('h:i', $dateinterval->format('%h:%I'));
        }
        
        return $this;
    }
    
    /**
     * Get heure_debut_eng
     *
     * @return time
     */
    public function getHeuredebutEng()
    {
        return $this->heure_debut_eng;
    }
    
    /**
     * Set heure_debut_eng
     *
     * @param datetime $temps
     * @return PlageHoraire
     */
    public function setHeuredebutEng($temps)
    {
        $this->heure_debut_eng = $temps;
    
        if($this->heure_fin_eng != null) {
            $date_fin = $this->heure_fin_eng;
            $diff = $date_fin->diff($this->heure_debut_eng);
            $this->temps = $diff;
        }
        
        return $this;
    }
    
    /**
     * Get temps
     *
     * @return time 
     */
    public function getTemps()
    {
        return $this->temps;
    }
    
    /**
     * Set temps
     *
     * @param datetime $temps
     * @return PlageHoraire
     */
    public function setTemps($temps)
    {
        $this->temps = $temps;
    
        return $this;
    }

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }
    
    /**
     * Set id
     *
     * @param interger $id
     * @return PlageHoraire
     */
    public function setId($id)
    {
        $this->id = $id;
    
        return $this;
    }
    
    /**
     * Set lib
     *
     * @param string $lib
     * @return PlageHoraire
     */
    public function setLib($lib)
    {
        $this->lib = $lib;
    
        return $this;
    }

    /**
     * Get lib
     *
     * @return string 
     */
    public function getLib()
    {
        return $this->lib;
    }
    
    /**
     * Get visibilite
     *
     * @return boolean 
     */
    public function getVisibilite()
    {
        return $this->visibilite;
    }
    
    /**
     * Set visibilite
     *
     * @param boolean $visibilite
     */
    public function setVisibilite($visibilite)
    {
        $this->visibilite = $visibilite;
    }
    
    /**
     * Get ordre
     *
     * @return integer 
     */
    public function getOrdre()
    {
        return $this->ordre;
    }
    
    /**
     * Set ordre
     *
     * @param interger $ordre
     * @return PlageHoraire
     */
    public function setOrdre($ordre)
    {
        $this->ordre = $ordre;
    
        return $this;
    }
}
